package lab03.test09;

import lab03.test09.Book;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lenovo on 2017/12/8.
 */
public class Client {
    public static void main(String[] args) {
        List<Book> books =new ArrayList<Book>();
        String path="D:\\book.txt";
        String path1="D:\\book1.txt";
        BufferedReader reader =null;
        BufferedWriter writer=null;
        try {
            reader=new BufferedReader(new FileReader(path));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        String line=null;
        try {
            while ((line=reader.readLine())!=null){
                String [] tokens=line.split("\t");
                Book book =new Book();
                Book.bookNo=Integer.parseInt(tokens[0]);
                book.bookName=tokens[1];
                book.version=tokens[2];
                book.price=Double.parseDouble(tokens[3]);
                book.sales=Double.parseDouble(tokens[4]);
                System.out.println(line);
                books.add(book);
            }
            int i=1;
            for(Book b:books){
                if(i==3){
                    b.price=b.price+20;
                }
                if(i==4){
                    b.price=b.price+20;
                }
                i++;
            }
            writer =new BufferedWriter(new FileWriter(path));
            for(Book b:books){
                writer.write(b.bookNo+"   "+b.bookName+"    "+b.version+"   "+b.price+" "+b.sales);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
